#!/bin/bash

which cmake || (
    echo "*** ERROR: We need cmake to compile.  Please install it."
    echo "  Package name: usually 'cmake'"
    echo "  Website: http://www.cmake.org"
)

# for cleanliness, do an out-of-source build
mkdir -p build
base=$PWD
(
echo "default:"
echo -e "\tcd build; make"
echo "install:"
echo -e "\tcd build; make install"
) > Makefile
cd build
# we have a bug: we need to run cmake twice at the moment.
cmake .. > /dev/null 2> /dev/null
cmake -DSTANDALONE:BOOL=TRUE -DUSE_GUI:BOOL=TRUE -DUSE_GD:BOOL=TRUE -DUSE_SDL:BOOL=TRUE -DENABLE_vcammod_ffmpeg_grabber:BOOL=TRUE -DENABLE_vcammod_ffmpeg_writer:BOOL=TRUE . || (
    cd $base
    rm -f Makefile
    exit 1
)
echo "To compile, type \"make\""
echo "To check/fix configuration, type \"ccmake build\""
